<?php
class NewsModel extends Model{
   /* 取新闻的方法 news表
	*$type   只能等于yicms
	* $id 可不传,自动获取GET的id.
	*/
	public function news($type,$id=-1){
		if($type != 'yicms') exit ('type必须为yicms');
		$news = $this->where("id = {$id}")->find();
		$id  = $news['id'];
		$pid = $news['pid'];
		$prev = $this->field('title,pid,id,time')->where("id < {$id} AND pid = {$pid}")->order('id DESC')->limit(1)->find();
		$next = $this->field('title,pid,id,time')->where("id > {$id} AND pid = {$pid}")->order('id ASC')->limit(1)->find();
		$news['mpic'] = C('URL').'/Public/product/m_'.$news['pic'];
		$news['spic'] = C('URL').'/Public/product/s_'.$news['pic'];
		$list = M('Nav')->field('id,name,dir')->where("id = {$pid}")->find();
		$news['name'] = $list['name'];
		$news['time'] = switchtime($news['time']);
		if(C('ISHTML')){
			$news['nurl'] = C('URL').'/'.$list['dir'];
			$data = M('Nav');
			$nav = $data->field('dir,conname')->where("id = $pid")->find();
			/*上一条*/
			$conname = str_replace('{id}',$prev['id'],$nav['conname']);
			$conname = str_replace('{Y}',date('Y',$prev['time']),$conname);
			if(empty($prev)) $news['prev']='没有了';
			else $news['prev']= '<a href="'.C('URL').'/'.$nav['dir'].'/'.$conname.'" tile="'.$prev['title'].'">'.$prev['title'].'</a>';
			/*下一条*/
			$conname = str_replace('{id}',$next['id'],$nav['conname']);
			$conname = str_replace('{Y}',date('Y',$next['time']),$conname);
			if(empty($next)) $news['next']='没有了';
			else $news['next']= '<a href="'.C('URL').'/'.$nav['dir'].'/'.$conname.'" tile="'.$next['title'].'">'.$next['title'].'</a>';
		}else{
			$news['nurl']= C('URL').'/index.php/Index/nlist/id/'.$list['id'];
			if(empty($prev)) $news['prev']='没有了';
			else $news['prev']= '<a href="'.C('URL').'/index.php/Index/news/id/'.$prev['id'].'" tile="'.$prev['title'].'">'.$prev['title'].'</a>';
			if(empty($next)) $news['next']='没有了';
			else $news['next']= '<a href="'.C('URL').'/index.php/Index/news/id/'.$next['id'].'" tile="'.$next['title'].'">'.$next['title'].'</a>';
		}
		return $news;
	}
}
?>